<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class Travels extends Model
{
    protected $table = 'travels';

    public function travels_reply()
    {
        return $this->hasMany(TravelsReply::class);
    }

    public function user()
    {
        return $this->belongsTo('App\Model\User','uid','id');
    }
    //利用『模型事件』来实现删除数据时的连带删除
    protected static function boot()
    {
        parent::boot(); // TODO: Change the autogenerated stub

        static::deleting(function ($travels){
           $travels->travels_reply()->delete();
        });
    }
}
